#ifndef MAINWINDOW_HXX
#define MAINWINDOW_HXX

#include <QMainWindow>
#include <QSlider>
#include <QLabel>
#include <QComboBox>
#include <QWidget>
#include <QPushButton>
#include <QLineEdit>
#include <QStandardItemModel>
#include <QTableView>
#include <QShortcut>

#include <Logging.hxx>
#include <VideoView.hxx>
#include <Sequence.hxx>
#include <VideoController.hxx>
#include <Project.hxx>


class TreeModel;
class QTreeView;
class QStandardItemModel;

class MainWindow : public QMainWindow
{
    Q_OBJECT
public:
    explicit MainWindow(QWidget *parent = nullptr);
	~MainWindow();

signals:

public slots :
	void updateTimeStamp();
	void updateFrameInfo();

	void openProject();
	void saveProject();
	void newProject();
	void exportYOLODataset();
	void exportFishDataset();
	void importProject();

	void addSequence();
	void removeSequence();
	void importSequences();

	void addClass();
	void removeClass();

    void treeDoubleClicked(const QModelIndex &index);

	void seekVideo(int pos);
	void goFrame();
	void goFrameIndex(int index);

	void goTime();
	void playOrPauseVideo();
	void playVideo();
	void pauseVideo();
	void clearRects();
	void startTrack();
	void stopTrack();
	void slowDown();
	void startObject();
	void endObject();
	void deleteObject();
	void rects2Objects();

	// zoom slots
	//void zoomArrow();
	//void zoomDrag();
	void zoomIn();
	void zoomFit();
	void zoomOut();
	void zoomFullScreen();

	void makeSingleFrameObjects();
	void makeNegativeSampleFrame();

	void nextFrame();
	void prevFrame();

	void updateTable();
	void updateTree();

	void updateSelectedTableRows();

	void selectObject();
	void unSelectObject();

	void hideSelectedObjects();
	void hideUnSelectedObjects();
	void showAllObjects();
	void mergeSelectedObjects();

	void selectRect();
	//void unSelectRect();

    void tableDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector<int> &roles = QVector<int>());
	//void tableRowActivated(const QModelIndex& index);
	void tableRowClicked(const QModelIndex& index);

	void createMainMenu();
	void createObjectsPanel();
	void createTrackerPanel();
	void createPlayerPanel();
	void createProjectPanel();

	void updateActiveSequence();

	void onKeySpace();
	
	void trackTypeChanged(int index);

	void help();
	void about();
public:
	void keyPressEvent(QKeyEvent* event);
private:
	QLayout* createPanelLayout();

private:
    VideoView* _view;
    Project* _project;

	VideoController* _controller;
	QSlider* _slider;

	QLabel* _labelTime;
	QLabel* _labelFrame;

	QPushButton* _btnPlay;
	QComboBox* _comboBox;
	QComboBox* _cbNetModel;

	QPushButton* _btnStartTrack;
	//QPushButton* _btnStopTrack;
	QPushButton* _btnRects2Objects;

	QPushButton* _btnMergeObjects;

	QPushButton* _btnHideUnSelectedObjects;
	QPushButton* _btnHideSelectedObjects;
	QPushButton* _btnSingleFrameObjects;
	QPushButton* _btnNegativeSampleFrame;

	QPushButton* _btnShowAllObjects;

	QPushButton* _btnDeleteObject;
	QPushButton* _btnStartObject;
	QPushButton* _btnEndObject;
	QPushButton* _btnClearRects;

	QPushButton* _btnSlow;
	QLineEdit* _linTargetTime;
	QLineEdit* _linTargetFrame;

	QAction* _actPlay;
	QAction* _actPause;
	QAction* _actPreviousFrame;
	QAction* _actNextFrame;

	QAction* _actStartTrack;
	QAction* _actRects2Objects;
	QAction* _actClearRect;

	QAction* _actMergeObject;
	QAction* _actDeleteObject;
	QAction* _actStartObject;
	QAction* _actEndObject;

	QAction* _actHideUnSelectedObjects;
	QAction* _actHideSelectedObjects;
	QAction* _actSingleFrameObjects;
	QAction* _actNegativeSampleFrame;
	QAction* _actShowAllObjects;

	QStandardItemModel* _tableViewModel;
	QTableView* _tableView;

	TreeModel* _treeModel;
    QTreeView* _treeView;

	QMenu* _dockerMenu;

	bool _isTracking;
};

#endif // MAINWINDOW_HXX
